﻿namespace WCBG.ToolsForUnity.Tools
{
    using System;
    using System.IO;
    using System.Runtime.InteropServices;

    public class FDirectory
    {
        public static bool ClearDirectory(string directory)
        {
            try
            {
                string[] files = Directory.GetFiles(directory);
                for (int i = 0; i < files.Length; i++)
                {
                    File.Delete(files[i]);
                }
                string[] directories = Directory.GetDirectories(directory);
                for (int j = 0; j < directories.Length; j++)
                {
                    Directory.Delete(directories[j], true);
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public static void CreateDirectory(string directory, bool isDeletOldPath = false)
        {
            if (Directory.Exists(directory))
            {
                if (isDeletOldPath)
                {
                    Directory.Delete(directory);
                    Directory.CreateDirectory(directory);
                }
            }
            else
            {
                Directory.CreateDirectory(directory);
            }
        }

        public static bool DeleteDirectory(string directory)
        {
            if (!Directory.Exists(directory))
            {
                return true;
            }
            bool flag = false;
            try
            {
                Directory.Delete(directory, true);
                flag = true;
            }
            catch (Exception)
            {
            }
            return flag;
        }

        public static bool Exists(string directory) => 
            Directory.Exists(directory);

        public static string[] GetDirectories(string path) => 
            Directory.GetDirectories(path);

        public static string[] GetFiles(string path) => 
            Directory.GetFiles(path);
    }
}

